// FileStorageManager.hpp
#pragma once

#include "Queue/Queue.hpp"
#include "camera_manage_type.h"
#include <atomic>
#include <condition_variable>
#include <ctime>
#include <mutex>
#include <queue>
#include <string>
#include <thread>
#include <vector>
class FileStorageManager {
  public:
    FileStorageManager(int cameraId, const StoreConfig &config);
    ~FileStorageManager();

    void initialize(const StoreConfig &config);
    void start();
    void stop();
    int enqueueImage(const FileFrameData &frameData);
    // void updateSyncFile(const std::string &formattedTime);

  private:
    int m_cameraId;
    StoreConfig m_config;
    Queue<FileFrameData> m_imageQueue;
    std::atomic<bool> m_running;
    std::string m_syncFile;
    int m_lastCameraNumber;
    std::thread m_storageThread;
    std::string m_lastNumberFile;
    void storageLoop();
    void storeImage(const FileFrameData &frameData);
    std::string generateFilename();
    void loadLastCameraNumber();
    void saveLastCameraNumber();
};
